package org.hd.config;

import cn.dev33.satoken.context.SaHolder;
import cn.dev33.satoken.filter.SaServletFilter;
import cn.dev33.satoken.interceptor.SaAnnotationInterceptor;
import cn.dev33.satoken.interceptor.SaRouteInterceptor;
import cn.dev33.satoken.router.SaHttpMethod;
import cn.dev33.satoken.router.SaRouter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/***
 * sa-token 配置类
 * 路由拦截器
 */
@Configuration
@EnableWebMvc
public class SaTokenConfigure implements WebMvcConfigurer {

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 注册Sa-Token的路由拦截器
        registry.addInterceptor(new SaRouteInterceptor())
                .addPathPatterns("/**") //拦截所有请求
                .excludePathPatterns(
                        "/user/doLogin",
                        "/user/getPublicKey");  //除了登录与获取私钥的接口开放

        // 注册注解拦截器，并排除不需要注解鉴权的接口地址 (与登录拦截器无关)
        //registry.addInterceptor(new SaAnnotationInterceptor()).addPathPatterns("/**");
    }


}
